package it.uniroma3.dia.ia.textcategorization.persistence;

import it.uniroma3.dia.ia.textcategorization.persistence.filesystem.FileSystemTextPersistenceManager;
import it.uniroma3.dia.ia.textcategorization.texcat.TexCatConfiguration;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * Factory class for TextPersistenceManager's instances polymorphic creation.
 * 
 * @author Marco Liceti.
 *
 */
public final class TextPersistenceManagerFactory {
	
	private static final Map<String, TextPersistenceManager> map = new HashMap<String, TextPersistenceManager>();
	
	/**
	 * Default TextPersistenceManager's name.
	 */
	public static final String DEFAULT = TexCatConfiguration.getDefaultTextPersistenceManager();
	/**
	 * FileSystemTextPersistenceManager's name.
	 */
	public static final String FILE_SYSTEM = "filesystem";
	
	static {
		map.put(FILE_SYSTEM, FileSystemTextPersistenceManager.getInstance());
	}
	
	/**
	 * @return the default TextPersistenceManager
	 */
	public static TextPersistenceManager getTextPersistenceManager() {
		return map.get(DEFAULT);
	}
	
	/**
	 * 
	 * @param textPersistenceManagerName
	 * @return the named TextPersistenceManager
	 */
	public static TextPersistenceManager getTextPersistenceManager(String textPersistenceManagerName) {
		return map.get(textPersistenceManagerName);
	}

}
